package com.fastCms.customer.frame.controller;

import com.fastCms.business.frame.busi.UserManageService;
import com.fastCms.business.frame.pojo.UserModel;
import com.fastCms.business.frame.pojo.po.*;
import com.fastCms.business.frame.pojo.vo.UserInfoVO;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.customer.frame.aspects.annotation.UserAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("api/user")
@Api(value = "ApiUserController", tags = "客户端-用户帐号管理")
public class ApiUserController {

    @Autowired
    private UserManageService userManageServiceImpl;

    @UserAccess
    @ApiOperation(value = "通用-登录", notes = "用户统一登录-checkType:验证方式:1-验证码登录 2-密码登录")
    @PostMapping(value = "/login")
    public ApiResponse<UserModel> login(@RequestBody UserLoginUserPO param, HttpServletRequest request) {
        ApiResponse apiResponse = userManageServiceImpl.login(param, request);
        return apiResponse;
    }

    @ApiOperation(value = "通用-注册前手机号码验证", notes = "注册前手机号码验证")
    @PostMapping(value = "/register/check")
    public ApiResponse<Boolean> registerCheck(@RequestBody ValidateCodeCheckPO param, HttpServletRequest request) {
        ApiResponse apiResponse = userManageServiceImpl.registerCheck(param, request);
        return apiResponse;
    }

    @ApiOperation(value = "通用-使用手机号码注册", notes = "手机手机号码注册用户")
    @PostMapping(value = "/register")
    public ApiResponse<UserModel> register(@RequestBody UserRegisterUserPO param) {
        ApiResponse apiResponse = userManageServiceImpl.register(param);
        return apiResponse;
    }

    @ApiOperation(value = "通用-我的基本信息", notes = "")
    @PostMapping(value = "/selfUserInfo")
    public ApiResponse<UserInfoVO> selfUserInfo() {
        ApiResponse apiResponse = userManageServiceImpl.selfUserInfo();
        return apiResponse;
    }

    @ApiOperation(value = "通用-完善我的信息", notes = "")
    @PostMapping(value = "/perfectInfo")
    public ApiResponse<Boolean> perfectInfo(@RequestBody UserPrefectInfoPO param) {
        ApiResponse apiResponse = userManageServiceImpl.perfectInfo(param);
        return apiResponse;
    }

    @ApiOperation(value = "通用-我的基本信息", notes = "")
    @PostMapping(value = "/infoByUserId")
    public ApiResponse<UserInfoVO> infoByUserId(@RequestBody IdStrPO param) {
        ApiResponse apiResponse = userManageServiceImpl.infoByUserId(param.getId());
        return apiResponse;
    }

    @ApiOperation(value = "通用-登出", notes = "")
    @PostMapping(value = "/logout")
    public ApiResponse<Boolean> logout() {
        ApiResponse apiResponse = userManageServiceImpl.logout();
        return apiResponse;
    }

    @ApiOperation(value = "通用-获取code", notes = "获取编号code")
    @PostMapping(value = "/wx/getCode")
    public ApiResponse<UserModel> wxGetCode(@RequestBody UserLoginUserPO userLoginUserPO, HttpServletRequest request) {
        ApiResponse apiResponse = userManageServiceImpl.wxGetCode(userLoginUserPO, request);
        return apiResponse;
    }

    @ApiOperation(value = "通用-微信用户注册", notes = "微信用户注册")
    @PostMapping(value = "/wx/userRegister")
    public ApiResponse<UserModel> wxUserRegister(@RequestBody WxUserRegisterPO wxUserRegisterPO, HttpServletRequest request) {
        ApiResponse apiResponse = userManageServiceImpl.wxUserRegister(wxUserRegisterPO, request);
        return apiResponse;
    }

}

